local Luatianxianjue = fk.CreateSkill({
  name = "Luatianxianjue",
  tags = {Skill.Compulsory}
})

Fk:loadTranslationTable{
  ["Luatianxianjue"] = "天仙决",
  [":Luatianxianjue"] = "锁定技。当你受到伤害后，若有伤害牌本回合你不会再受到来自此牌同名牌的伤害。你的回合外受到伤害时，你弃置一个“分身”防止之并摸两张牌",
  ["@tianxianjue-turn"] = "天仙决",
}

Luatianxianjue:addEffect(fk.DamageInflicted, {
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(Luatianxianjue.name) and data.card then
        
        return table.contains(player:getTableMark("@tianxianjue-turn"), data.card.trueName) or (player.phase == Player.NotActive and player:getMark("@shen") > 0)
    end
  end,
  on_use = function(self, event, target, player, data)
    if table.contains(player:getTableMark("@tianxianjue-turn"), data.card.trueName) then
      data:preventDamage()
    end
    if player:getMark("@shen") > 0 and player.phase == Player.NotActive then
      player.room:removePlayerMark(player,"@shen")
      player:drawCards(2)
      data:preventDamage()
    end
  end,
})



Luatianxianjue:addEffect(fk.Damaged, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(Luatianxianjue.name) and data.card
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(player,"@tianxianjue-turn",data.card.trueName)
  end,
})

return Luatianxianjue 